/******************************************************************************
 *      Mestrado em Ciência da Computação - UFMS
 *		Redes de Computadores - Prof. Dr. Ronaldo Alves Ferreira
 *		Alunos: Geraldo Landre, Marcel Tolentino, Vinícius Bueno
 *****************************************************************************/
/* tcpwait.c - tcpwait */

#include "thread.h"

#include "my_socket.h"
#include "tcbtab.h"
#include "tcpfms.h"
#include "tcb.h"

extern int tcpkilltimers(struct tcb *ptcb);
extern int tmset(int port, int portlen, void *msg, int time);

/*------------------------------------------------------------------------
 *  tcpwait - (re)schedule a DELETE event for 2MSL from now
 *------------------------------------------------------------------------
 */
int tcpwait(struct tcb *ptcb)
{
	int	tcbnum = ptcb - (struct tcb *)&tcbtab[0];

	tcpkilltimers(ptcb);
	tmset(thread_getport(output_thread), TCPQLEN, MKEVENT(DEL, tcbnum), TCP_TWOMSL);
	return OK;
}
